package com.huike.game.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.huike.game.Activity.Game10ImageDesc;
import com.huike.game.R;
import com.huike.game.base.Game10Grid;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public class game10Image extends Fragment {
    private GridView gvGame10;
    private List<Game10Grid> list;
    private adapterView adapter;



    @Nullable
    @Override
    public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        list = new ArrayList<>();
        list.add(new Game10Grid(R.drawable.image,"图片名称"));
        list.add(new Game10Grid(R.drawable.image,"图片名称"));
        list.add(new Game10Grid(R.drawable.image,"图片名称"));
        list.add(new Game10Grid(R.drawable.image,"图片名称"));
        list.add(new Game10Grid(R.drawable.image,"图片名称"));
        View view = View.inflate(getContext(), R.layout.game10grid, null);
        gvGame10 = (GridView) view.findViewById(R.id.gv_game10);

        adapter = new adapterView();
        gvGame10.setAdapter(adapter);

        gvGame10.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Game10Grid grid = list.get(i);
                int image = grid.getImage();

//                创建图片详细页面
                Intent intent = new Intent(getActivity(),Game10ImageDesc.class);
                intent.putExtra("image",image);
                //网络地址形式
//                intent.putExtra("image","http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg");
                startActivity(intent);

            }
        });

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    class adapterView extends BaseAdapter{

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int i) {
            return list.get(i);
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            viewHolder holder = null;
            if(view == null){
                holder = new viewHolder();
                view = View.inflate(getContext(),R.layout.game10gridbuju,null);
                holder.mIvGame10Image = (ImageView) view.findViewById(R.id.iv_game10_image);
                holder.mTvGame10Text = (TextView) view.findViewById(R.id.tv_game10_text);
                view.setTag(holder);

            }else{
                holder = (viewHolder) view.getTag();
            }

            Game10Grid grid = list.get(i);
            holder.mIvGame10Image.setImageResource(grid.getImage());
            holder.mTvGame10Text.setText("视频名称");

            return view;
        }
    }

    class viewHolder{
        ImageView mIvGame10Image;
        TextView mTvGame10Text;
    }
}
